package com.pureut.system.controller;

import java.util.Arrays;
import java.util.List;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.pureut.common.core.web.controller.BaseController;
import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.core.web.page.TableDataInfo;
import com.pureut.system.domain.ProductBatchReporting;
import com.pureut.system.domain.ProductionWorkOrder;
import com.pureut.system.domain.vo.ProductionWorkOrderVo;
import com.pureut.system.service.IProductionWorkOrderService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * @Author: pureut
 * @Date: 2025-04-09 16:30:36
 * @Desc: 生产工单表Controller
 */
@RestController
@RequestMapping("/system/productionWorkOrder")
public class ProductionWorkOrderController extends BaseController {

    /**
     * 生产工单表Service
     */
    @Resource
    private IProductionWorkOrderService productionWorkOrderService;

    /**
     * 查询生产工单表列表
     * @param: params 参数列表
     * @return: Json工具类对象
     */
    //    @SaCheckPermission("productionWorkOrder-list")
    @GetMapping("/list")
    public TableDataInfo list( ProductionWorkOrderVo productionWorkOrderVo) {
        startPage();
        LambdaQueryWrapper<ProductionWorkOrder> resultQuery = new LambdaQueryWrapper<ProductionWorkOrder>();
        if(ObjectUtil.isNotNull(productionWorkOrderVo.getOrderNo())){
            resultQuery.like(ProductionWorkOrder::getOrderNo, productionWorkOrderVo.getOrderNo());
        }
        if(ObjectUtil.isNotNull(productionWorkOrderVo.getDemandQuantity())){
            resultQuery.eq(ProductionWorkOrder::getDemandQuantity, productionWorkOrderVo.getDemandQuantity());
        }
        if(ObjectUtil.isNotNull(productionWorkOrderVo.getEstimatedKitQuantity())){
            resultQuery.eq(ProductionWorkOrder::getEstimatedKitQuantity, productionWorkOrderVo.getEstimatedKitQuantity());
        }

        return getDataTable(productionWorkOrderService.list(resultQuery));
    }


    /**
     * 获取生产工单表详细信息
     * @param: id 生产工单表主键
     * @return: Json工具类对象
     */
    //    @SaCheckPermission("productionWorkOrder-query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(productionWorkOrderService.getById(id));
    }

    /**
     * 新增生产工单表
     * @param: productionWorkOrder 生产工单表对象
     * @return: Json工具类对象
     */
    //    @SaCheckPermission("productionWorkOrder-add")
    @PostMapping
    public AjaxResult add( @RequestBody ProductionWorkOrderVo productionWorkOrderVo) {
        return toAjax(productionWorkOrderService.save(productionWorkOrderVo));
    }

    /**
     * 修改生产工单表
     * @param: productionWorkOrder 生产工单表对象
     * @return: Json工具类对象
     */
    //    @SaCheckPermission("productionWorkOrder-edit")
    @PutMapping
    public AjaxResult edit( @RequestBody ProductionWorkOrderVo productionWorkOrderVo) {
        return toAjax(productionWorkOrderService.updateById(productionWorkOrderVo));
    }

    /**
     * 删除生产工单表
     * @param: id 生产工单表主键
     * @return: Json工具类对象
     */
    //    @SaCheckPermission("productionWorkOrder-remove")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(productionWorkOrderService.removeByIds(Arrays.asList(ids)));
    }
}
